import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';

@Injectable()
export class LoggingInterceptor implements NestInterceptor {
   intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
      console.log('拦截器开始...');

      const now = Date.now();
      return next
         .handle()
         .pipe(
            tap(() => { 
               console.log(`拦截器结束... ${Date.now() - now}ms`) 
            }),
         );
   }
}